#!/bin/python
# -*- coding: gb2312; mode:python ; tab-width:4 -*- ex:set tabstop=4 shiftwidth=4 expandtab: -*-

'''
Created on 2011-11-20

@author: cyb
'''
from threading import Thread
from time import sleep


class timeoutThread(Thread):
    def __init__(self,message_source):
        Thread.__init__(self)
        self.message_source=message_source
        self.sendlist=[]
    def run(self):
        print "running"
    def run1(self):
        while 1:
            
            sleep(2)
            self.sendlist=self.message_source.getCommandList()
            if self.sendlist:
                for i in self.sendlist:
                    if i.getState()==0:
                        i.setState(9)
                    elif i.getState()==9:
                        print "time out!"
                        try:
                            if i.getRetransmitTime()<3:
                                self.message_source.sendCommand(i.getSendedPacket())
                                i.setRetransmitTime(int(i.getRetransmitTime())+1)
                            else:
                                self.message_source.removeFromCommandList(i)
                        except:
                            print "error in timeout thread!"
                    else:
                        pass
            
            
        
if __name__=="__main__":
    s=timeoutThread(1)
    s.start()

    